﻿using ConsoleApp.Infrastructure.Attributes;
using ConsoleApp.Infrastructure.CanalCore.Infrastructure.Models;
using ConsoleApp.Infrastructure.Rmq;
using ConsoleApp.Infrastructure.TaskFramework;
using ConsoleApp.Job.Model.Entities;
using ConsoleApp.Util;
using Newtonsoft.Json;
using System;

namespace ConsoleApp.Job.TaskJob.队列消费
{
    [TaskInterceptor("RmqCanal消费任务", TaskLevel.One)]
    public class RmqCanal消费任务 : TaskBase
    {
        public static string Canal消息
        {
            get
            {
                return "Xigua.Shusi.Canal";
            }
        }

        public override void Execute()
        {
			while (true)
            {
                new RmqCanal消费任务_RMQ(RmqQueueManager.Connect, Canal消息).HandleOneMessage();
            }
        }

        public class RmqCanal消费任务_RMQ : OneConsumerWorkerBase<CanalEntity<T1>>
        {
            public RmqCanal消费任务_RMQ(RmqOption connection, string queueName) : base(connection)
			{
                Console.Title = queueName;
                QueueName = queueName;
            }

            protected override bool HandleComingMessage(CanalEntity<T1> entity)
            {
                ConsoleHelper.WriteWarningLine($"Canal消息:{JsonConvert.SerializeObject(entity)}");
                return true;
            }
        }
    }
}
